//
//  MKHotActorCell.swift
//  MOKOAnnounce
//
//  Created by 曹相召 on 2017/7/11.
//  Copyright © 2017年 cc.moko. All rights reserved.
//  最热艺人cell

import UIKit

class MKHotActorCell: MKBaseTableViewCell ,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    
    var collectionView:UICollectionView!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        let layout:UICollectionViewFlowLayout = UICollectionViewFlowLayout.init()
        layout.minimumLineSpacing = 5
        layout.minimumInteritemSpacing = 5
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSize.init(width: 150, height: 200)
        self.collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
        self.collectionView.showsHorizontalScrollIndicator = false
        self.collectionView.backgroundColor = UIColor.white
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        self.collectionView.register(MKHotActorSubCell.classForCoder(), forCellWithReuseIdentifier: "MKHotActorSubCell")
        self.contentView.addSubview(self.collectionView)
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:MKHotActorSubCell = collectionView.dequeueReusableCell(withReuseIdentifier: "MKHotActorSubCell", for: indexPath) as! MKHotActorSubCell
        return cell
    }
//    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
//        return UIEdgeInsetsMake(8, 5, 8, 5)
//    }
    override func layoutSubviews() {
        super.layoutSubviews()
//        self.collectionView.frame = CGRect.init(x: 5, y: 0, width: ScreenWidth - 10, height: self.contentView.height)
        self.collectionView.frame = self.contentView.bounds
        self.collectionView.contentInset = UIEdgeInsetsMake(0, 5, 0, 5)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class MKHotActorSubCell: UICollectionViewCell {
    var icon:UIImageView!
    var name:UILabel!
    var tip:UILabel!
    var signOne:UILabel!
    var signTwo:UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColorFromRGB(rgbValue: 0xf0f0f0, A: 1)
        
        self.icon = UIImageView.init()
        self.icon.image = UIImage.init(named: "newHome_hotActor_bottomBlack")
        self.icon.contentMode = .scaleAspectFill
        self.icon.layer.cornerRadius = 8
        self.icon.clipsToBounds = true
//        self.icon.backgroundColor = UIColor.randomColor()
        self.contentView.addSubview(self.icon)
        
        self.name = UILabel.label(fontSize: 14, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
        self.name.backgroundColor = UIColor.randomColor()
        self.name.text = "谁说遥远太遥远"
        self.contentView.addSubview(self.name)
        
        self.tip = UILabel.label(fontSize: 10, textColor: UIColorFromRGB(rgbValue: 0x333333, A: 1))
        self.tip.backgroundColor = UIColor.randomColor()
        self.tip.text = "天下第一美女"
        self.contentView.addSubview(self.tip)
        
        self.signOne = UILabel.label(fontSize: 11, textColor: UIColorFromRGB(rgbValue: 0xffffff, A: 1))
        self.signOne.text = "聪明"
        self.signOne.textAlignment = .center
        self.signOne.layer.cornerRadius = 5
        self.signOne.layer.borderColor = UIColor.white.cgColor
        self.signOne.layer.borderWidth = 0.5
        self.contentView.addSubview(self.signOne)
        
        self.signTwo = UILabel.label(fontSize: 11, textColor: UIColorFromRGB(rgbValue: 0xffffff, A: 1))
        self.signTwo.text = "古灵精怪"
        self.signTwo.textAlignment = .center
        self.signTwo.layer.cornerRadius = 5
        self.signTwo.layer.borderColor = UIColor.white.cgColor
        self.signTwo.layer.borderWidth = 0.5
        self.contentView.addSubview(self.signTwo)
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.icon.frame = self.contentView.bounds
        
        self.signOne.sizeToFit()
        self.signTwo.sizeToFit()
        self.signOne.frame = CGRect.init(x: (self.contentView.width - self.signOne.width - self.signTwo.width - 10 - 20) * 0.5, y: self.icon.bottom - 10 - 17, width: self.signOne.width + 10, height: 17)
        
        self.signTwo.frame = CGRect.init(x: self.signOne.right + 10, y: self.icon.bottom - 10 - 17, width: self.signTwo.width + 10, height: 17)
        
        self.tip.sizeToFit()
        self.tip.frame = CGRect.init(x: (self.contentView.width - self.tip.width) * 0.5, y: self.signOne.top - 6 - self.tip.height, width: self.tip.width, height: self.tip.height)
        
        self.name.sizeToFit()
        self.name.frame = CGRect.init(x: (self.width - self.name.width) * 0.5, y: self.tip.top - 6 - self.name.height, width: self.name.width, height: self.name.height)
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
